//
//  HMBasicController.swift
//  HMSlender
//
//  Created by 赵少朋赵少朋 on 17/1/17.
//  Copyright © 2017年 ITheima. All rights reserved.
//

import UIKit

class HMBasicController: UIViewController {

    lazy var tabView = UITableView()
    
    let isLogin:Bool = HMOAuthModel.shared.isLogin
    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    
    func setNoLoginNavUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: nil, title: "注册", target: self, action: #selector(registerItemClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(imgName: nil, title: "登陆", target: self, action: #selector(registerItemClick))
    }
    
    override func loadView() {
        
        let index = tabBarController?.selectedIndex
        
        if isLogin {
            
            //登陆状态
            view = tabView
        } else {
            setNoLoginNavUI()
            switch index {
            case let i where i == 0:
                let landingView = HMLandingView(frame: UIScreen.main.bounds, vcIndex: i ?? 0)
                landingView.closure = {()->() in
                    
                    self.registerItemClick()
                }
                view = landingView
            case let i where i == 1:
                view = HMLandingView(frame: UIScreen.main.bounds, vcIndex: i ?? 0)
            case let i where i == 2:
                view = HMLandingView(frame: UIScreen.main.bounds, vcIndex: i ?? 0)
            case let i where i == 3:
                view = HMLandingView(frame: UIScreen.main.bounds, vcIndex: i ?? 0)
            default:
                break
            }
            
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - 注册item点击事件
    func registerItemClick() -> Void {
        
        //已经关联
        let OAuthVC = HMOAuthController()
        //创建个导航控制器 根控制器为OauthVc 模态到对应的控制器
        present(HMNavigationController(rootViewController:OAuthVC), animated: true, completion: nil)
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
